import java.io.File;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Transaction 
{

	public Transaction(
			int transactionId,
			String transactionType,
			String memberId,
			String itemId,
			double fineAmount) 
	{
		this.transactionId = transactionId;
		this.transactionDate = new Date();
		this.transactionType = transactionType;
		this.memberId = memberId;
		this.itemId = itemId;
		this.fineAmount = fineAmount;
	}
	
	public Transaction(String transactionFromFile) throws ParseException 
	{
		String [] transactionTokens = transactionFromFile.split(";");
		this.transactionId = Integer.parseInt(transactionTokens[0]);
		DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm");
		this.transactionDate = df.parse(transactionTokens[1]);
		this.transactionType = transactionTokens[2];
		this.memberId = transactionTokens[3];
		this.itemId = (transactionTokens[4] == null ? "" : transactionTokens[4]);
		this.fineAmount = Double.parseDouble(transactionTokens[5]);
	}
	


	private int transactionId;
	private Date   transactionDate;
	private String transactionType;
	private String memberId;
	private String itemId;
	private double fineAmount;
	
	public boolean isACheckoutTransaction() 
	{
		if(this.transactionType.equalsIgnoreCase("TT_CHECKOUT_ITEM"))
			return true;
		return false;
	}
	public Date getDate()
	{
		return this.transactionDate;
	}
	public String getItemId() 
	{
		return this.itemId;
	}
	public boolean isAFinePayTransaction() 
	{
		if(this.transactionType.equalsIgnoreCase("TT_PAY_FINE"))
			return true;
		return false;
	}
	public double getFineAmout() 
	{
		return this.fineAmount;
	}
	public String toString()
	{
		DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm"); 
		return "\t" + this.transactionId + "\t" + df.format(this.transactionDate) + "\t" + this.transactionType + "\t" + this.memberId + "\t" + this.itemId + "\t" + this.fineAmount;
	}

	public String serializeTransaction() 
	{
		DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm");
		String writeTrasactionRow = this.transactionId + ";" + df.format(this.transactionDate) + ";" + this.transactionType + ";" + this.memberId + ";" + this.itemId + ";" + this.fineAmount;
		return writeTrasactionRow;
	}

	
}
